package demo3;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDo {
    public static final String[] strall={"♥","♦","♣","♠"};
    public List<Card> cardList=new ArrayList<>();
    //买牌
    public List<Card> buyCard(){
        for(int i=1;i<=13;i++){
            for(int j=0;j<4;j++){
                int rank=i;
                Card card=new Card(strall[j],rank);
                cardList.add(card);
            }
        }
        return cardList;
    }
    //洗牌
    public void washCard(List<Card> cardListc){
        Random random=new Random();
        for (int i=cardList.size()-1;i>0;i--){
            int rank1= random.nextInt(i);
            swap(cardList,i,rank1);
        }
    }
    public void swap(List<Card> cardList,int i,int rank1){
        Card temp=cardList.get(i);
        cardList.set(i,cardList.get(rank1));
        cardList.set(rank1,temp);
    }
    //发牌
    public List<List<Card>> play(List<Card> cardList){
        List<List<Card>> list=new ArrayList<>();
        List<Card> list0=new ArrayList<>();
        List<Card> list1=new ArrayList<>();
        List<Card> list2=new ArrayList<>();
        list.add(list0);
        list.add(list1);
        list.add(list2);
        for(int i=0;i<5;i++){
            for(int j=0;j<3;j++){
               Card card=cardList.remove(0);
               list.get(j).add(card);
            }
        }

        return list;
    }
}
